<?php
declare (strict_types=1);

namespace app\common\model\system;

use app\common\model\BaseModel;

/**
 * @mixin \think\Model
 */
class User extends BaseModel
{
    protected $name = 'system_user';



    public function getInfo($id)
    {
        $info = parent::getInfo($id);
        unset($info['password']);
        $info['avatar'] = IMG_URL.$info['avatar'];
        return $info;
    }
    /**
     * 获取用户权限节点
     * @param $user_id
     * @return array
     */
    public function getNodeList($user_id)
    {
        $nodeList = [];
        if ($user_id == 1) {
            $map[] = ['status', 1];
        } else {
            $user = $this->getInfo($user_id);
            if (!empty($user) && !empty($user['role_ids'])) {
                $role_nodes = app(RoleNode::class)->getList([['role_id', 'in', $user['role_ids']]]);
                $node_ids = array_column($role_nodes, 'node_id');
                $map[] = ['id', 'in', $node_ids];
            }else{
                return $nodeList;
            }
        }
        $nodes = app(Node::class)->getList($map);
        $nodeList = array_column($nodes, 'node');
        return $nodeList;
    }

}
